/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.kylingroup.J2SE.Reflection;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
 *
 * @author kylin
 */
public class Say {
     
    public void say(String methodStr,String name, int age) throws SecurityException, IllegalArgumentException, NoSuchMethodException, IllegalAccessException, InvocationTargetException{
    //  Method method = this.getClass().getMethod("say" + methodStr, new Class[]{String.class,int.class});              //1
        Method method = this.getClass().getDeclaredMethod("say" + methodStr, new Class[]{String.class,int.class});      //2
        method.invoke(this, new Object[]{name,age});
    }
     
    public void sayHello(String name, int age){
        System.out.println("hello " + name + ",I know you are " + age);
    }
     
    protected void sayHi(String name, int age){
        System.out.println("hi " + name + ",I know you are " + age);
    }
     
    private void sayBye(String name, int age){
        System.out.println("bye " + name + ",I know you are " + age);
    }
     
}
